import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;

import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class IOExceptionTest {
    public static void main(String[] args) {
//        try{
//            IOExceptionTest.method();
//        } catch (IOException e) {
//            System.out.println("Main方法中的捕获处理");
//            e.printStackTrace(System.out);
//        }
        try {
            IOExceptionTest.upMethod();

        } catch (IOException e) {
            System.out.println("Main方法中的捕获处理");
            e.printStackTrace(System.out);
        }
    }

    public static void upMethod() throws IOException {

//        try {
//            method();
//        } catch (IOException e) {
//            System.out.println("upMethod方法中的捕获处理");
//            e.printStackTrace(System.out);
//            throw e;
//        }
        method();
        System.out.println("执行剩下的代码");
    }

    public static void method() /*throws IOException*/ {
        /*try {
            File file = new File("data.txt");
            System.out.println(file.exists());
            if (!file.exists()) {
                throw new IOException("文件创建失败");
            }
        } catch (IOException e) {
            throw e;
        }*/

        File file = new File("data.txt");
        System.out.println(file.exists());
//        try {
//            FileOutputStream fileOutputStream = new FileOutputStream(file);
//        } catch (IOException e) {
//            e.printStackTrace(System.out);
//        }

        try {
            boolean success = file.createNewFile();
            System.out.println(success);
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            fileOutputStream.write('a');
        } catch (IOException e) {
            e.printStackTrace(System.out);
        }



    }
}
